import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
} from '@nestjs/common';
import { PermissionService } from './permission.service';
import {
  ApiResponse,
  ApiOperation,
  ApiTags,
  ApiBearerAuth,
} from '@nestjs/swagger';

import { PermissionEntity } from './entities/permission.entity';
import { CreatePermissionDto } from './dto/create-permission.dto';
import { UpdatePermissionDto } from './dto/update-permission.dto';
import { ListPermissionReturn } from './dto/list-permission.dto';
import { JwtAuthGuard } from '../../common/guards/jwt.guard';

@ApiTags('权限模块')
@ApiBearerAuth()
@Controller('menu')
@UseGuards(JwtAuthGuard)
export class PermissionController {
  constructor(private readonly permissionService: PermissionService) {}

  @Post()
  @ApiOperation({ summary: '创建权限' })
  @ApiResponse({ type: PermissionEntity })
  create(@Body() createPermissionDto: CreatePermissionDto) {
    return this.permissionService.create(createPermissionDto);
  }

  @Get('list')
  @ApiOperation({ summary: '查询权限列表' })
  @ApiResponse({ type: ListPermissionReturn })
  findAll(): Promise<ListPermissionReturn> {
    return this.permissionService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '查询权限详情' })
  @ApiResponse({ type: PermissionEntity })
  findOne(@Param('id') id: string): Promise<PermissionEntity> {
    return this.permissionService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新权限' })
  @ApiResponse({ example: 'success' })
  update(
    @Param('id') id: string,
    @Body() updatePermissionDto: UpdatePermissionDto,
  ) {
    return this.permissionService.update(id, updatePermissionDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除权限' })
  @ApiResponse({ example: 'success' })
  remove(@Param('id') id: string) {
    return this.permissionService.remove(id);
  }
}
